<template>
  <div>
    <a-modal v-model="visible" @ok="handleOk" @cancel="handleOk" :width="1200" class="full-modal">
      <div class="modal-title">
        <div class="title-left">PSD设备实时视图</div>
        <div class="title-right">
          <span>所属站台：{{result.lineName}}/{{result.platformName}}</span>
          <span>所属位置：{{result.deviceLocation}}</span>
          <span>设备名称：{{result.deviceCode}}</span>
          <span>所属类别：{{result.deviceCategory}}</span>
        </div>
      </div>
      <div class="top-cont" v-if="partsVOList.length">
        <div v-if="DZS">
          <span class="deviceType" @click="toPartsDetail(DZS)">电子锁</span>
          <ul>
            <li v-for="(e,i) in DZS.instructionsList" :key="i">
              <i :class="e.status == 1?'green':''"></i>
              {{e.instructionsName}}
            </li>
          </ul>
          <div class="connecting-line"></div>
          <div class="vertical-line"></div>
          <div :class="['spot' ,DZS.healthyStatus!=='健康'?'orange':'']"></div>
        </div>
        <div v-if="LCB">
          <span class="deviceType" @click="toPartsDetail(LCB)">LCB</span>
          <ul>
            <li v-for="(e,i) in LCB.instructionsList" :key="i">
              <i :class="e.status == 1?'green':''"></i>
              {{e.instructionsName}}
            </li>
          </ul>
          <div class="connecting-line"></div>
          <div class="vertical-line"></div> 
          <div class="transverse-line"></div>
          <div :class="['spot' ,LCB.healthyStatus!=='健康'?'orange':'']"></div>

        </div>
        <div v-if="DJ">
          <span class="deviceType" @click="toPartsDetail(DJ)">电机</span>
          <ul>
            <li v-for="(e,i) in DJ.instructionsList" :key="i">
              <i :class="e.status == 1?'green':''"></i>
              {{e.instructionsName}}
            </li>
          </ul>
          <div class="connecting-line"></div>
          <div :class="['spot' ,DJ.healthyStatus!=='健康'?'orange':'']"></div>
        </div> 
        <div v-if='hdm'>
          <span class="deviceType" @click="toPartsDetail(hdm)">滑动门</span>
          <div class="menti">
            <ul>
              <li  v-for="(e,i) in (hdm.instructionsList).filter((e,i)=>i<4)" :key="i">
                  <i :class="e.status == 1?'green':''"></i>
                  {{e.instructionsName}}
              </li>
            </ul>
            <ul>
              <li v-for="(e,i) in (hdm.instructionsList).filter((e,i)=>i>3)" :key="i">
                    <i :class="e.status == 1?'green':''"></i>
                    {{e.instructionsName}}
              </li>    
            </ul>
            <div class="connecting-line"></div>
            <div class="vertical-line"></div>
          <div :class="['spot' ,hdm.healthyStatus!=='健康'?'orange':'']"></div>
          </div>

        </div>                
        <div>
          <span class="deviceType" @click="toPartsDetail(MT)">门体</span>
          <div class="menti" v-if="MT">
            <ul>
              <li v-for="(e,i) in (MT.instructionsList).filter((e,i)=>i<5)" :key="i">
                  <i :class="e.status == 1?'green':''"></i>
                  {{e.instructionsName}}
              </li>
            </ul>
            <ul>
              <li v-for="(e,i) in (MT.instructionsList).filter((e,i)=>i>4)" :key="i">
                  <i :class="e.status == 1?'green':''"></i>
                  {{e.instructionsName}}
              </li>
            </ul>
            <div class="connecting-line"></div>
            <div class="vertical-line"></div>
            <div :class="['spot' ,MT.healthyStatus!=='健康'?'orange':'']"></div>

          </div>

        </div>


        <div class="bus">

          <span :class="result.deviceStatus =='正常'?'bgGreen':'bgRed'"></span>
          <p :class="result.deviceStatus =='正常'?'colorGreen':'colorRed'">{{result.deviceStatus=='正常'?'CAN总线正常':'CAN总线故障'}}</p>

          <span :class="result.netStatus =='正常'?'bgGreen':'bgRed'"></span>
          <p :class="result.netStatus =='正常'?'colorGreen':'colorRed'">{{result.netStatus =='正常'?'485总线正常':'485总线故障'}}</p>
        </div>
      </div>
      <!-- <img src="../../../assets/full.png" alt=""> -->

      <img style="height:65px;padding-top:20px;" src="@/assets/full5.png" alt="">
      <div class="imgWarp">
        <div class="left">
          <img src="@/assets/full1.png" alt="">
          <img :style="{'right':`${doorOpening}%`}" src="@/assets/full2.png" alt="">
        </div>
        <div class="right">
          <img :style="{'left':`${doorOpening}%`}" src="@/assets/full3.png" alt="">
          <img src="@/assets/full4.png" alt="">
        </div>
      </div> 

      <div class="bottom-cont" v-if="partsVOList.length">
        <div :style="{'visibility':!zYJM?'hidden':''}" class="bot-item">
          <span class="deviceType" @click="toPartsDetail(zYJM)">应急门</span>
          <ul v-if="zYJM&&zYJM.instructionsList.length">
            <li v-for="(e,i) in zYJM.instructionsList" :key="i">
              <i :class="e.status == 1?'green':''"></i>
              {{e.instructionsName}}
            </li>
          </ul>
        </div>
        <div class="bot-item">
          <span class="deviceType" @click="toPartsDetail(HW)">红外</span>
          <ul>
            <li v-for="(e,i) in HW.instructionsList" :key="i">
              <i :class="e.status == 1?'green':''"></i>
              {{e.instructionsName}}
            </li>
          </ul>
          <div class="connecting-line"></div>
          <div :class="['spot' ,HW.healthyStatus!=='健康'?'orange':'']"></div>
        </div>
        <div class="bot-item sensor">
          <span class="deviceType" @click="toPartsDetail(MWCGQ)">门位置传感器</span>
          <div v-if="MWCGQ">
            <ul>
              <li v-for="(e,i) in MWCGQ.instructionsList" :key="i">
                <i :class="e.status == 1?'green':''"></i>
                {{e.instructionsName}}
              </li>
            </ul>
            <div class="connecting-line"></div>
            <div :class="['spot' ,MWCGQ.healthyStatus!=='健康'?'orange':'']"></div>
          </div>

        </div>
        <div style="visibility: hidden;" class="bot-item">
          <span class="deviceType" @click="toPartsDetail(HW)">红外</span>
          <ul>
            <li v-for="(e,i) in HW.instructionsList" :key="i">
              <i :class="e.status == 1?'green':''"></i>
              {{e.instructionsName}}
            </li>
          </ul>
          <div class="connecting-line"></div>
          <div :class="['spot' ,HW.healthyStatus!=='健康'?'orange':'']"></div>
        </div>
        <div v-if='yYJM' class="bot-item">
          <span class="deviceType" @click="toPartsDetail(yYJM)">应急门</span>
          <div>
            <ul>
              <li v-for="(e,i) in yYJM.instructionsList" :key="i">
                <i :class="e.status == 1?'green':''"></i>
                {{e.instructionsName}}
              </li>
            </ul>
          </div>
        </div>
      </div>
      <p class="moreBtn" v-if="!showMore">
        <a @click='handleShowMore'>查看更多</a>
      </p>
      <div v-if="showMore" class="moreWarp">
        <div class="topContent">
          <div class="leftWarp">
            <div class="moreItem" v-for='(e,i) in leftData' :key="i">
              <div class="typeTitle">{{e.name}}</div>
              <div class="tContent">
                <div class="rowItem" v-for='(v,j) in e.details' :key="j">
                  <div class="statusWarp">
                    <span style='display:flex'>
                      <div class="title">{{v.title}}</div>
                      <div class="value">{{v.value}}</div>
                    </span>

                    <div class="unit">{{v.unit}}</div>
                  </div>
                  <div class="tip">{{v.tip}}</div>
                </div>
              </div>
            </div>
          </div>
          <div class="rightWarp">

            <div class="moreItem" v-for='(e,i) in rightData' :key="i">
              <div class="typeTitle">{{e.name}}</div>
              <div class="rowItem" v-for='(v,j) in e.details' :key="j">
                <div class="statusWarp">
                  <span style='display:flex'>
                    <div class="title">{{v.title}}</div>
                    <div class="value">{{v.value===''?'--':v.value}}</div>
                  </span>
                  <div class="unit">{{v.unit}}</div>
                </div>
                <div  class="tip">{{v.tip}}</div>
              </div>
            </div>
          </div>
        </div>

        <div class="bottomWarp">
          <div class="moreItem" v-for='(e,i) in bottomData' :key="i">
            <div class="typeTitle">{{e.name}}</div>
              <div class="botContent">
                <div class="rowItem" v-for='v in (e.details).filter((k,i)=>i<3)' :key="v.title">
                  <div class="statusWarp">
                    <span style='display:flex'>
                      <div class="title">{{v.title}}</div>
                      <div class="value">{{v.value}}</div>
                    </span>

                    <div class="unit">{{v.unit}}</div>
                  </div>
                  <div class="tip">{{v.tip}}</div>
                </div>
                <div style='width:270px' v-for="i in 1" :key="i"></div>
                <div class="rowItem" v-for='v in (e.details).filter((k,i)=>i>=3)' :key="v.title">
                  <div class="statusWarp">
                    <span style='display:flex'>
                      <div class="title">{{v.title}}</div>
                      <div class="value">{{v.value}}</div>
                    </span>

                    <div class="unit">{{v.unit}}</div>
                  </div>
                  <div class="tip">{{v.tip}}</div>
                </div>                
              </div>
          </div>
        </div>

      </div>
    </a-modal>
  </div>
</template>
<script>
import { getAction } from '@/api/manage'
export default {
  data() {
    return {
      visible: false,
      partsVOList: [],
      timers: null,
      result: {},
      MT: null,
      DJ: null,
      DZS: null,
      LCB: null,
      zYJM: null,
      yYJM: null,
      HW: null,
      MWCGQ: null,
      showMore: false,
      leftData: null,
      rightData: null,
      bottomData: null,
      doorOpening:0
    };
  },
  props: ['fullId'],
  watch: {
    fullId(val) {
      if (val) {
        console.log('所有部件==>全高', val)
        this.getInfo(val)
        this.timers = setInterval(() => {
          setTimeout(() => {
            this.getInfo(val)
          }, 0);
        }, 300)
      }
    }
  },
    mounted(){

      // 模拟数据
    // let doorOpening=0
    // let myTimer =  setInterval(()=>{
    //      doorOpening+=Math.random()*10*2
    //       if(doorOpening<=0){
    //         doorOpening = 0
    //         clearInterval(myTimer)

    //       }else if(doorOpening>100){
    //         doorOpening = 0
    //       }
    //       this.doorOpening = doorOpening /2
    //   },300)

    },  
  methods: {
    getInfo(id) {
      getAction('/statistics/queryDataBoardDCU', { id }).then(res => {
        if (res && res.code == 200) {
          this.result = res.result

          // 开 --- 关
          //    0 --- 100.00
          let doorOpening = res.result.doorOpening || 0
          if(doorOpening<=0){
            doorOpening = 0
          }else if(doorOpening>100){
            doorOpening = 100
          }  
          this.doorOpening = doorOpening / 2
            


          this.partsVOList = res.result.partsVOList

          let psdParamVOList = res.result.psdParamVOList
          console.log('this.psdParamVOList>>>>', psdParamVOList)
          this.leftData = res.result.psdParamVOList.filter((e, i) => i == 0)
          console.log('this.leftData>>>',this.leftData)
          this.rightData = psdParamVOList.filter((e, i) => i > 0 && i<(psdParamVOList.length-1))
          this.bottomData = psdParamVOList.filter(e => e.name=='电机诊断数据')
          console.log('this.bottomData>>>>', this.bottomData)


          this.MT = this.partsVOList.filter(item => item.partsName == 'A门')[0]
          this.DJ = this.partsVOList.filter(item => item.partsName == 'A门电机')[0]
          this.DZS = this.partsVOList.filter(item => item.partsName == 'A门电子锁')[0]
          this.MWCGQ = this.partsVOList.filter(item => item.partsName == 'A门位置传感器')[0]

          this.hdm = this.partsVOList.filter(item=>item.partsName == '滑动门')[0]

          this.LCB = this.partsVOList.filter(item => item.partsName == 'LCB')[0]
          this.HW = this.partsVOList.filter(item => item.partsName == '红外')[0]
          // this.zYJM = this.partsVOList.filter(item => item.partsName == '左应急门')[0]
          // this.yYJM = this.partsVOList.filter(item => item.partsName == '右应急门')[0]

          let zM = this.partsVOList.filter(item=>item.partsName == '左应急门')[0]
          let yM = this.partsVOList.filter(item=>item.partsName == '右应急门')[0]
          this.zYJM = zM
          this.yYJM = yM   
          if(zM&&zM.reverse==1){
            this.zYJM = yM
            this.yYJM = zM
          }
          if(yM&&yM.reverse==1){
            this.zYJM = yM
            this.yYJM = zM
          }
        }
      })
    },
    handleOk() {
      clearInterval(this.timers)
      this.timers = null
      this.$emit('clearId')
      this.showMore = false
      this.visible = false;
    },
    toPartsDetail(data) {
      // console.log('PSD部件详情id==》》',data) 
      if(data.partsName=='滑动门') return
      clearInterval(this.timers)
      this.timers = null
      this.$router.push({ path: '/equipment/equipmentList/dcuDetail', query: { id: data.partsId, fName: this.result.deviceCode, type: data.partsName, isHome:true} })
    },
    handleShowMore() {
      this.showMore = true
    },    
  },
};
</script>
<style lang="less" scoped>
/deep/ .ant-modal {
  top: 30px !important;
}
.modal-title {
  padding-bottom: 24px;
  border-bottom: 1px solid #e9e9e9;
  display: flex;

  .title-left {
    font-size: 16px;
    font-weight: 500;
    color: #000;
    margin-right: 20px;
  }

  .title-right {
    line-height: 24px;
    font-size: 14px;
    color: rgba(0, 0, 0, 0.4);

    span {
      display: inline-block;
      margin-right: 50px;
    }
  }
}

.top-cont,
.bottom-cont {
  display: flex;
  justify-content: space-around;
  margin-top: 10px;
  // border: 1px solid red;

  > div {
    border: 1px solid #e9e9e9;
    // padding: 5px 20px;
    border-radius: 2px;
    position: relative;

    .transverse-line,.vertical-line,.connecting-line,.spot{
        z-index: 3;
      }

    .connecting-line {
      width: 0;
      border-left: 2px dashed #1890ff;
      height: 50px;
      position: absolute;
      left: 50%;
      bottom: -50px;
    }

    .spot {
      width: 24px;
      height: 24px;
      position: absolute;
      border-radius: 50%;
      background-color: rgba(24, 144, 255, 0.3);
      border: 2px solid #1890ff;
      left: 40%;
      bottom: -74px;

      &.orange {
        background: #f5a623;
        box-shadow: 0px 2px 8px 1px rgba(245, 166, 35, 0.65);
        border: 2px solid #ffffff;
      }
    }

    .menti {
      display: flex;

      .connecting-line {
        left: 70%;
        bottom: -50px;
      }

      .spot {
        background-color: rgba(24, 144, 255, 0.3);
        border: 2px solid #1890ff;
        left: 66%;
        bottom: -74px;
      }

      ul:first-child {
        margin-right: 10px;
      }
    }

    &.bot-item {
      .connecting-line {
      }
      .spot {
        left: 38%;
      }
    }
    &.bot-item.sensor {
      .connecting-line {
      }
      .spot {
        // left: 40%;
        // top: -44px;
      }
    }

    span {
      font-size: 14px;
      color: #000;
      font-weight: 500;
      // margin-bottom: 20px;
      display: block;
    }

    ul {
      margin: 0;
      padding: 10px 20px 0 10px;

      li {
        list-style: none;
        margin-bottom: 8px;

        i {
          width: 8px;
          height: 8px;
          display: inline-block;
          border-radius: 50%;
          background: #dcdcdc;

          &.warning {
            background-color: #ff3823;
          }
        }
      }
    }
  }
  .green {
    background: #52c41a;
  }
  .bus {
    padding: 26px 35px;
    text-align: center;
    color: #7bcd0f;

    span {
      display: block;
      width: 24px;
      height: 24px;
      margin: 0 auto;
      background: #7bcd0f;
      border-radius: 50%;
      margin-bottom: 6px;

      // &:nth-child(2) {
      //   margin-top: 50px;
      // }
      &.fault {
        background: #ff3823;
      }

      &.healthy {
        background: #7bcd0f;
      }
      &.warning {
        background: #f5a623;
      }
    }
    .bgRed {
        background: #FF3823;
      }      
    .bgGreen {
      background: #7BCD0F;
    }
    .colorGreen{
      color: #7BCD0F;
    }
    .colorRed {
      color: #FF3823;
    }
  }
}
.top-cont {
  > div {
    &:nth-child(1) {
      // left: -30px;
      .connecting-line {
        height: 50px;
        top: 190px;
      }
      .vertical-line {
        position: absolute;
        width: 200px;
        height: 40px;
        top: 240px;
        left: 70px;
        border-top: 2px dashed #1890ff;
      }
      .spot {
        left: 270px;
        bottom: -65px;
      }
    }
    &:nth-child(2) {
      // left: -30px;
      .connecting-line {
        height: 20px;
        top: 190px;
      }
      .vertical-line {
        position: absolute;
        width: 107px;
        height: 40px;
        top: 210px;
        left: 49px;
        border-top: 2px dashed #1890ff;
      } 
      .transverse-line {
        position: absolute;
        border-left: 2px dashed #1890FF;
        height: 17px;
        top: 212px;
        left: 154px;
        }           
      .spot {
        left: 143px;
        bottom: -65px;
      }
    }
    &:nth-child(3) {
      // left: -90px;
      .connecting-line {
        height: 40px;
        top: 190px;
      }
      .spot {
        left: 38px;
        bottom: -65px;
      }
    }
    &:nth-child(4) {
      // left: -90px;
      .connecting-line {
        height: 40px;
        top: 190px;
        left: 92px;

      }
      .spot {
        left: 81px;
        bottom: -65px;
      }
    }
    &:nth-child(5) {
      .connecting-line {
        height: 50px;
        top: 190px;
        left: 32px;

      }
      .vertical-line {
        position: absolute;
        width: 70px;
        height: 40px;
        top: 240px;
        left: -36px;
        border-top: 2px dashed #1890ff;
      }       
      .spot {
        left: -60px;
        bottom: -65px;
      }
    }    
  }
}
.bottom-cont {
  > div {
    &:nth-child(2) {
      left: -120px;
      .connecting-line {
        height: 60px;
        top: -60px;
      }
      .spot {
        left: 38%;
        top: -84px;
      }
    }
    &:nth-child(3) {
      left: -245px;
      .connecting-line {
        height: 50px;
        top: -50px;
        left: 63px;
      }
      .spot {
        top: -74px;
      }
    }
    &:nth-child(4) {
      left: 120px;
      // border: 1px solid red;
      .connecting-line {
        height: 60px;
        top: -60px;
      }
      .spot {
        top: -84px;
      }
    }
  }
}
img {
  width: 100%;
  height: 300px;
  // padding-top: 20px;
}
.deviceType {
  background: #fafafa;
  text-align: center;
  line-height: 32px;
}
.moreBtn {
  text-align: center;
  margin: 20px 0 0;
  font-size: 18px;
  user-select: none;
}

.moreWarp {
  display: flex;
  flex-direction: column;
  margin-top: 10px;
  // border: 1px solid red;
  .topContent{
    display: flex;
    justify-content: space-between;
  // border: 1px solid red;

  }
  .moreItem {
    border: 1px solid #e9e9e9;
    margin-bottom: 10px;
  }
  .typeTitle {
    background: #fafafa;
    padding: 0 15px 0 10px;
    line-height: 32px;
    text-align: center;
  }
  .rowItem {
    width: 270px;
    height: 44px;
    // border: 1px saddlebrown solid;
    padding: 5px 10px;
    .statusWarp {
      display: flex;
      justify-content: space-between;
      .title {
        width: 150px;
        // border: 1px solid red;
        // text-align: justify;
        // text-align-last:justify;
        // text-justify: distribute-all-lines;
      }
      .value {
        width: 60px;
        // border: 1px solid #52c41a;
        text-align: left;
        color: #52c41a;
      }
      .unit {
      }
    }
    .tip {
      font-size: 14px;
      color: #cac6ca;
    }
  }
}
.tContent {
  // border:1px solid red;
  display: flex;
  flex-direction: column;
  height: 400px;
  flex-wrap: wrap;
  // .rowItem {
  //   margin: 0 10px;
  // }
}
.leftWarp {
  // margin-right:10px ;
  width: 49%;
}
.rightWarp {
  width: 49%;
  // border: 1px solid red;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
}
.bottomWarp {
  width: 100%;
  .botContent {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    .rowItem {
      // width: 220px;
      // border: 1px saddlebrown solid;
      padding: 5px 10px 5px 10px;
      height: 33px;
      .statusWarp {
        display: flex;
        justify-content: space-between;
        .title {
          width: 150px;
          // border: 1px solid red;
        }
        .value {
          width: 130px;
          // border: 1px solid #52c41a;
          text-align: left;
          color: #52c41a;
        }
        .unit {
        }
      }
      .tip {
        font-size: 14px;
        color: #cac6ca;
      }
    } 
  }

} 
.imgWarp{
  height:300px;
  width:100%;
  display: flex;
  align-items: center;
  overflow: hidden;
  div{
    width:50%;
    display: flex;
    align-items: center;
    position: relative;
    img{
      position: absolute;
      transition: all ease .7s
    }

  }
  

  .left{
    img:nth-child(1){
      z-index: 1;
      width:57%;
      left:0;

    }
    img:nth-child(2){
      width:45%;
      right:0;
    }
  }

  .right{
    img:nth-child(1){
    width:45%;
    left:0;

    }
    img:nth-child(2){
      z-index: 1;
      width:57%;
      right:0;

    }
  }

}
</style>